<template>
  <div class="app-container">
    <!-- 添加或修改甲方信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body v-drag-fullscreen>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-row :gutter="20">
                <el-col :span="8" :xs="24">
                <el-form-item label="合同类型ID" prop="contractCategoryId">
                    <el-input v-model="form.contractCategoryId" placeholder="请输入合同类型ID" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="甲方名称" prop="partyName">
                    <el-input v-model="form.partyName" placeholder="请输入甲方名称" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="甲方手机号" prop="partyPhone">
                    <el-input v-model="form.partyPhone" placeholder="请输入甲方手机号" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="联系人" prop="partyContacts">
                    <el-input v-model="form.partyContacts" placeholder="请输入联系人" :disabled="disabled"/>
                </el-form-item>
            </el-col>
                <el-col :span="8" :xs="24">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="disabled"/>
                </el-form-item>
            </el-col>
              </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getFirstParty , addFirstParty, updateFirstParty } from "@/api/lease/firstParty";

export default {
  name: "FirstPartyFrom",
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否禁用
      disabled: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {

  },
  methods: {
    show(option){
      this.reset();
      this.disabled = option.type == 'VIEW'
      if(option.type=='ADD'){
          this.open = true;
          this.title = "新增甲方信息管理";
      }else if(option.type == 'UPDATE' || option.type == 'VIEW'){
          getFirstParty(option.id).then(response => {
              this.form = response.data;
                                                                                                                                                                                                                                                                                                                                                            
              if(option.type == 'VIEW'){
                  this.title = "查看甲方信息管理";
              }else{
                  this.title = "修改甲方信息管理";
              }
              this.open = true;
          });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.$emit("cancel")
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractCategoryId: null,
        partyName: null,
        partyPhone: null,
        partyContacts: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFirstParty(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.cancel()
            });
          } else {
            addFirstParty(this.form).then(response => {
              this.msgSuccess("新增成功");
                this.cancel()
            });
          }
        }
      });
    }
  }
};
</script>
